//
//  CihuiCell.m
//  Learn
//
//  Created by apple on 2024/4/2.
//  Copyright © 2024 迟建国. All rights reserved.
//

#import "CihuiCell.h"

@interface CihuiCell ()

@property (nonatomic, strong) UIImageView    * bgImg;
@property (nonatomic, strong) UILabel    * stateLabel;
@property (nonatomic, strong) UILabel    * titleLabel;
@property (nonatomic, strong) UILabel    * nianjiLabel;
@property (nonatomic, strong) UILabel    * numLabel;

@end

@implementation CihuiCell
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.bgImg];
    }
    return self;
}

- (UILabel *)numLabel {
    if(!_numLabel){
        _numLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, self.nianjiLabel.bottom + 5, self.width - 20, 20)];
        _numLabel.textColor = [UIColor whiteColor];
        _numLabel.font = [UIFont systemFontOfSize:12];
        _numLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _numLabel;
}

- (UILabel *)nianjiLabel {
    if(!_nianjiLabel){
        _nianjiLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, self.titleLabel.bottom + 21, self.width - 20, 20)];
        _nianjiLabel.textColor = [[UIColor whiteColor]colorWithAlphaComponent:0.7];
        _nianjiLabel.font = [UIFont systemFontOfSize:12];
        _nianjiLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _nianjiLabel;
}
- (UILabel *)titleLabel {
    if(!_titleLabel){
        _titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 2+ self.stateLabel.bottom, self.width - 40, 48)];
        _titleLabel.numberOfLines = 0;
        _titleLabel.textColor = [UIColor whiteColor];
        _titleLabel.font = [UIFont systemFontOfSize:14];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _titleLabel;
}
- (UILabel *)stateLabel {
    if(!_stateLabel){
        _stateLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.width - 54, -4, 50, 20)];
        _stateLabel.backgroundColor = rgbHex(0xF45555, 1);
        _stateLabel.text = @"学习中";
        _stateLabel.textColor = [UIColor whiteColor];
        _stateLabel.font = [UIFont systemFontOfSize:12];
        _stateLabel.textAlignment = NSTextAlignmentCenter;
        _stateLabel.layer.borderColor = UIColor.whiteColor.CGColor;
        _stateLabel.layer.borderWidth = 1;
        _stateLabel.layer.cornerRadius = 10;
        _stateLabel.layer.masksToBounds = YES;
        _stateLabel.hidden = YES;
    }
    return _stateLabel;
}

- (UIImageView *)bgImg {
    if(!_bgImg){
        _bgImg = [[UIImageView alloc]initWithFrame:CGRectMake(0, 4, self.width,self.height - 4)];
        _bgImg.contentMode = UIViewContentModeScaleAspectFill;
        [_bgImg addSubview:self.stateLabel];
        [_bgImg addSubview:self.titleLabel];
        [_bgImg addSubview:self.nianjiLabel];
        [_bgImg addSubview:self.numLabel];
    }
    return _bgImg;
}


- (void)setSelectID:(NSString *)selectID {
    _selectID = selectID;
}
- (void)updateItemCellModel:(id)ItemModel {
    if ([ItemModel isKindOfClass:CiHuiModel.class]) {
        CiHuiModel *model = (CiHuiModel *)ItemModel;
        NSString *imageName = @"cihuibg_1";
        if ([model.gradeName containsString:@"七年级"] || [model.gradeName containsString:@"一年级"] ||
            [model.gradeName containsString:@"四年级"]) {
            imageName = @"cihuibg_1";
        }else if ([model.gradeName containsString:@"八年级"] || [model.gradeName containsString:@"二年级"] ||
                  [model.gradeName containsString:@"五年级"]) {
            imageName = @"cihuibg_2";
        }else{
            imageName = @"cihuibg_3";
        }
        self.bgImg.image = [UIImage imageNamed:imageName];
        self.stateLabel.hidden = ![self.selectID isEqualToString:model.ID];
        self.titleLabel.text = model.versionFullName;
        self.nianjiLabel.text = model.gradeName;
        self.numLabel.text = [NSString stringWithFormat:@"%@个单词",model.wordsCount];;
    }
}
@end
